package com.android.delivery.activity.siji

import android.app.Activity
import android.content.Intent
import androidx.recyclerview.widget.RecyclerView
import com.android.delivery.adapter.siji.SJOrderAdapter
import com.android.delivery.api.ApiService
import com.android.delivery.base.BaseListActivity
import com.android.delivery.callback.DialogCallback
import com.android.delivery.callback.LzyResponse
import com.android.delivery.entity.Transport
import com.android.delivery.util.DensityUtil
import com.darsh.multipleimageselect.helpers.Constants
import com.lzy.okgo.model.Response

/**
 * @author: mqwang
 * @create: 2/27/21 1:04 PM
 * @Description: 待上车
 */
class WaitBusActivity : BaseListActivity<Transport>() {
    private val sjOrderAdapter: SJOrderAdapter by lazy {
        SJOrderAdapter(1)
    }

    override fun bindRecyclerView(recLv: RecyclerView?) {
        setMainTitle("待上车")

        recLv?.setPadding(0, DensityUtil.dp2px(12f), 0, 0)
        recLv?.adapter = sjOrderAdapter

        sjOrderAdapter.setOnItemChildClickListener { adapter, view, position ->
            var item = sjOrderAdapter.data.get(position)
            WaitBusDetailsActivity.self(mContext as Activity, item, Constants.REQUEST_CODE)
        }
    }

    override fun loadData(page: Int, pageCount: Int) {
        ApiService.transport(this, 1, object : DialogCallback<LzyResponse<List<Transport>>>() {
            override fun onSuccess(response: Response<LzyResponse<List<Transport>>>?) {
                onGetDataSuc(response!!.body().data)
            }
        })
    }

    override fun getData(): MutableList<Transport> {
        return sjOrderAdapter.data
    }

    override fun bindData(isRefresh: Boolean, list: MutableList<Transport>?) {
        if (isRefresh) sjOrderAdapter.setNewData(list) else sjOrderAdapter.addData(list!!)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (requestCode == Constants.REQUEST_CODE) {
            if (resultCode == Activity.RESULT_OK) {
                getData()
            }
        }
    }
}